package com.common.security.config;

import com.netty.game.nettygame.interfaces.util.MD5Util;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Component;

@Component
public class CustomPasswordEncoder implements PasswordEncoder {

    private static final String PREFIX = "custom_prefix_";
    @Override
    public String encode(CharSequence rawPassword) {
        // 这里可以实现自定义加密逻辑
        String customHash = PREFIX + rawPassword; // 自定义逻辑示例
        return MD5Util.encode(customHash); // 使用BCrypt进行加密
    }

    @Override
    public boolean matches(CharSequence rawPassword, String encodedPassword) {
        // 这里实现自定义匹配逻辑
        String customHash = PREFIX + rawPassword; // 自定义逻辑示例
        return MD5Util.verifyPassword(customHash,encodedPassword);
    }

    public String encode(String password,String salt) {
    	return this.encode(password+salt);
    }
}
